# -*- coding: utf-8 -*-
"""
Created on Sat Aug 12 22:28:37 2023

@author: skunk69
"""

import json

chinese_name = u'流调用抑郁自评量表'
english_name = 'Center for Epidemiological Survey, Depression Scale'
abbreviation = 'CES-D'
category = u'精神病学临床量表'

outline = u"""《流调用抑郁自评量表》由美国国立精神卫生研究所Radloff编制于1977年，原名为流行学研究中心抑郁量表（Center for Epidemiological Survey, Depression Scale, CES-D）。此表较广泛地用于流行学调查，用以筛查出有抑郁症状的对象，以便进一步检查确诊。也有人用作临床检查，评定抑郁症状的严重程度。和其他抑郁自评量表相比,CES-D更着重于个体的情绪体验，较少涉及抑郁时的躯体症状。《流调用抑郁自评量表》中文版参考张明园（1990）的译本。"""

instruction = u"""下面是一些您可能有过或感觉到的情况或想法。请按照过去一星期内您的实际情况或感觉填写。"""

with open('CES-D.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    f.close()

items = {}
for key,line in enumerate(lines):
    _,value = line.strip().split('）',maxsplit=1)
    items[key+1] = value.strip()

reverse_items = [4,8,12,16]
scales = []
scales_items = []
factors = []
factors_scales = []
rating = [u'没有或几乎没有',u'少有',u'常有',u'几乎一直有']
score_rules = list(range(0,4))

contents = {
    'instruction':instruction,
    'items':items,
    'reverse_items':reverse_items,
    'scales':scales,
    'scales_items':scales_items,
    'factors':factors,
    'factors_scales':factors_scales,
    'rating':rating,
    'score_rules':score_rules       
    }

implementation = u"""CES-D为自评量表，按照过去一周内出现相应情况或感觉的频度评定：不足一天者为“没有或几乎没有”，1~2天者为“少有”，3~4天者为“常有”，5~7天者为“几乎一直有”。"""

reliability = u"""量表原作者对CES-D信度进行检验，alpha系数在0.9以上，重测信度系数间隔四周为0.67，间隔一年为0.32。"""
validity = u"""CES-D与医护人员用Hamilton抑郁量表评分的相关性系数为0.44。"""
measurements = {'reliability':reliability,'validity':validity}

interpretation = u"""首先将反向题目反向计分，然后将所有条目得分相加得到总分。总分小于等于15分为无抑郁症状，16~19分为可能有抑郁症状，大于等于20分为有抑郁症状。"""

applications = u"""量表协作组应用CES-D做常模研究，均值为11.52。"""

this_scale = {
    'chinese_name':chinese_name,
    'english_name':english_name,
    'abbreviation':abbreviation,
    'category':category,
    'outline':outline,
    'contents':contents,
    'implementation':implementation,
    'measurements':measurements,
    'interpretation':interpretation,
    'applications':applications    
    }

with open(abbreviation+'.json','w+',encoding='utf-8') as f:
    json.dump(this_scale,f,indent=2,ensure_ascii=False)